package com.jackrain.nea.fc.cp.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.jdbc.SQL;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 店务考勤系统-营业员调店
 * Mapper
 *
 * @author WSL
 * @create 2017/11/20
 */
@Mapper
public interface ViewCtranapplyMapper {

    class SelectPro
    {
        public String selectProvider(Map map)
        {
            return new SQL()
            {
                {
                    SELECT("CP_C_SALER_ID,CP_C_STORE_ID,CP_C_DEST_ID,TRANDATE");
                    FROM("CP_C_TRANAPPLY");
                    Object[] list = (Object[]) map.get("list");
                    StringBuilder sb = new StringBuilder("(");
                    for (Object num : list) {
                        sb.append(num).append(",");
                    }
                    sb.deleteCharAt(sb.length()-1).append(")");
                    WHERE("ID IN "+sb.toString());
                }
            } .toString();
        }
    }

    /**
     * 根据param查询条件 查询【调店申请】表
     * @param param
     * @return String
     */
    @SelectProvider(type = SelectPro.class, method = "selectProvider")
    List<HashMap> selectProvider(@Param("list") Object[] param);

    /**
     * 外键关联表：CP_C_EMP 取值字段：ECODE
     * @param id
     * @return
     */
    @Select("SELECT ECODE FROM CP_C_EMP WHERE ID = #{id}")
    String getSalerEcode(Long id);

    /**
     * 外键关联表：CP_C_STORE 取值字段：ECODE
     * @param id
     * @return
     */
    @Select("SELECT ECODE FROM CP_C_STORE WHERE ID = #{id}")
    String getStoreEcode(Long id);

}
